package com.frogs.ucenter.controller;

import java.util.Arrays;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.util.ApplicablePlatformEnum;
import com.frogs.ucenter.component.UserPermissionHelper;
import com.frogs.ucenter.entity.UserBaseAccountInfo;
import com.frogs.ucenter.service.BrowsingService;
import com.frogs.ucenter.service.CouponService;
import com.frogs.ucenter.service.FavoriteService;
import com.frogs.ucenter.service.GoodsService;
import com.frogs.ucenter.service.ShoppingCartService;
import com.frogs.ucenter.service.UserService;

@Controller
public class IndexController extends BaseController3 {
	private static Logger log = LoggerFactory.getLogger(IndexController.class);    
	
	public static final String URI_INDEX = "/index";
    private static final String INDEX_VIEW = "/index";
    
    @Resource
    private UserService userService;
    
    @Resource
    private ShoppingCartService shoppingCartService;
    
    @Resource
    private GoodsService goodsService;
    
    @Resource
    private CouponService couponService;
    
    @Resource
    private BrowsingService browsingService;
    
    @Resource
    private FavoriteService favoriteService;



    @Resource
    private UserPermissionHelper userPermissionHelper;

    @RequestMapping(URI_INDEX)
    public String index(HttpServletRequest request,HttpServletResponse response,ModelMap model) {
    	
    	
		
    	UserBaseAccountInfo user = userPermissionHelper.getUser(request);
    	
		try {
			//用户信息模块
	    	model.put("user", userService.getUserBaseInfoForMap(user.getId()));
	    	
	    	//用户购物车
	    	model.put("shoppingCartGoods", shoppingCartService.getShoppingCartList(user.getId(), ApplicablePlatformEnum.WEB.getId(), 1, 3));

		} catch (Exception e) {
			log.error("func[index] parameterMap[{}] exception[{} - {}] desc[fail]",//
					new Object[] { request.getParameterMap(), e.getMessage(), Arrays.deepToString(e.getStackTrace()) });
			
			request.setAttribute("errorMessage", e.getMessage());
			return ERROR_VIEW;
		}
        return INDEX_VIEW;
    }

}